import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Cookies from "js-cookie";

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/',
    name: 'home',
    component: HomeView,
    redirect: '/index',
    children: [
      {
        path: 'index',//注意此处不能加 /
        name: "homePage",
        component: () => import('../views/home/index.vue') //动态加载小区管理页面
      },
      {
        path: 'cashier',//注意此处不能加 /
        name: "cashier",
         component:()=>import('../views/charge/cashier')
     
      }
      ,
      {
        path: 'deposit',//注意此处不能加 /
        name: "deposit",
         component:()=>import('../views/charge/deposit')
     
      }
      ,
      {
        path: 'linshi',//注意此处不能加 /
        name: "linshi",
         component:()=>import('../views/charge/linshi')
     
      }
      ,
      {
        path: 'advance',//注意此处不能加 /
        name: "advancce",
         component:()=>import('../views/charge/advance')
     
      }
    ]
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// //全局路由守卫
// router.beforeEach((to,from,next) => {
//   if (to.path == '/login' || to.path == '/register') {
//   next();
//   } else {
//   const username = Cookies.get("username");
//   console.log(username)
//   if (username == null || username == undefined ||
//   username == '') {
//   router.push('/login');
//   } else {
//   next();
//   }
//   }
//   })



export default router
